<template>
  <div id="app2">
    <el-container>
      <el-aside width="200px">
        <el-row class="tac">
          <el-col :span="12" id="left">
            <el-menu default-active="2" class="el-menu-vertical-demo">
              <el-menu-item index="3">
                <span slot="title">欢迎光临:&nbsp;{{ username }}</span>
              </el-menu-item>
              <el-menu-item index="1">
                <i class="el-icon-menu"></i>
                <span slot="title">首页</span>
              </el-menu-item>
              <el-submenu index="2">
                <template slot="title">
                  <div>
                    <i class="el-icon-document"></i>
                    <span class="span">页面管理</span>
                  </div>
                </template>
                <el-menu-item-group>
                  <el-menu-item index="1-1" id="el" @click="myshop1"
                    >我的商铺</el-menu-item
                  >
                  <el-menu-item index="1-2" id="el" @click="myshop2"
                    >添加商铺</el-menu-item
                  >
                  <el-menu-item index="1-3" id="el" @click="myshop3"
                    >商铺管理</el-menu-item
                  >
                  <el-menu-item index="1-4" id="el" @click="myshop4"
                    >食品管理</el-menu-item
                  >
                  <el-menu-item index="1-5" id="el" @click="myshop5"
                    >订单管理</el-menu-item
                  >
                </el-menu-item-group>
              </el-submenu>
            </el-menu>
          </el-col>
        </el-row>
      </el-aside>
      <el-main>
        <el-breadcrumb separator="/">
          <el-breadcrumb-item :to="{ path: '/index' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item><a href="#">业务管理</a></el-breadcrumb-item>
          <el-breadcrumb-item>添加商铺</el-breadcrumb-item>

          <el-dropdown>
            <span class="el-dropdown-link">
              个人中心<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <v-nav></v-nav>
            </el-dropdown-menu>
          </el-dropdown>
        </el-breadcrumb>
        <div class="div">
          <strong>店铺名称:</strong
          ><el-input v-model="shopname" placeholder="请输入内容"></el-input>
        </div>
        <div class="div">
          <strong>店铺地址:</strong
          ><el-input v-model="addr" placeholder="请输入内容"></el-input>
        </div>
        <div class="div">
          <strong>店铺电话:</strong
          ><el-input v-model="tel" placeholder="请输入内容"></el-input>
        </div>
        <div class="div">
          <strong>店铺图片:</strong>

          <el-upload
            class="upload-demo"
            drag
            name="filename"
            action="/api/uploads"
            multiple
            :on-success="success"
          >
            <img :src="url" alt="" />
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">
              将文件拖到此处，或<em>点击上传</em>
            </div>
            <div class="el-upload__tip" slot="tip">
              只能上传jpg/png文件，且不超过500kb
            </div>
          </el-upload>
        </div>
        <div @click="quick"><el-button type="primary">立即创建</el-button></div>
      </el-main>
    </el-container>
  </div>
</template>

<script>
import nav from "../../components/nav.vue";
import addshopModel from "../../model/addshopModel";
export default {
  components: {
    "v-nav": nav
  },
  data() {
    return {
      dialogImageUrl: "",
      dialogVisible: false,
      disabled: false,
      input: "",
      username: "",
      user_id: "", //绑定登录的用户
      shopname: "", //商铺名称
      shoppic: "", //商铺图片
      addr: "", //商铺地址
      tel: "", //,
      url: ""
    };
  },
  created() {
    console.log(11);
    let info = window.localStorage.getItem("info");
    console.log(info);
    this.username = info;
  },
  methods: {
    success(res, file, fileList) {
      console.log(res);
      window.localStorage.setItem("url", res.url);
    },
    async quick() {
      let shoppic = window.localStorage.getItem("url");
      this.url = shoppic;
      let shopname = this.shopname;
      let addr = this.addr;
      let tel = this.tel;
      if (shoppic && shopname && addr && tel) {
        let data = { shopname, addr, tel, shoppic };
        console.log(data);
        let list = await addshopModel.add(data);
        console.log(list);
      } else {
        alert("请输入内容");
      }
    },
    myshop1() {
      this.$router.push("/shops/myshop");
    },
    myshop2() {
      this.$router.push("/shops/add");
    },
    myshop3() {
      this.$router.push("/shops/shop");
    },
    myshop4() {
      this.$router.push("/shops/food");
    },
    myshop5() {
      this.$router.push("/shops/order");
    },
    handleRemove(file) {
      console.log(file);
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    handleDownload(file) {
      console.log(file);
    }
  }
};
</script>

<style scoped>
#el {
  color: #fff;
}
.span {
  background-color: rgb(10, 6, 51);
}
.el-menu-item.is-active {
  background-color: rgb(10, 6, 51);
}
.div {
  margin-bottom: 20px;
}
.el-breadcrumb {
  border-bottom: 1px solid gray;
  margin-bottom: 20px;
}
.el-main {
  padding: 0;
  margin-left: 20px;
}
.el-aside {
  overflow: hidden;
}
</style>
